package com.tj.collection.controller.admin.request;

import com.fqgj.common.api.ParamsObject;
import com.fqgj.exception.common.ApiIllegalArgumentException;
import com.tj.collection.db.domain.Admin;
import com.tj.collection.db.enums.AdminTypeEnum;
import org.hibernate.validator.constraints.NotEmpty;

// import com.fqgj.exception.common.ApiIllegalArgumentException;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2017/3/11
 * Time: 下午5:35
 */
public class AdminRegisterVO extends ParamsObject {

    private static final long serialVersionUID = -564372423249003773L;

    @NotEmpty(message = "账号不能为空")
    private String account;

    @NotEmpty(message = "密码不能为空")
    private String password;

    @NotEmpty(message = "用户名不能为空")
    private String name;

    @NotEmpty(message = "手机号必填")
    private String mobile;

    private String phone;

    private Integer type;

    @Override
    public void validate() {
        if (AdminTypeEnum.getEnumByType(type) == null) {
            throw new ApiIllegalArgumentException("用户类型错误");
        }

    }

    public Admin transform2Admin() {
        return new Admin()
                .setName(this.name)
                .setAccount(this.account)
                //.setPassword(this.password)
                .setMobile(this.mobile)
                .setAdminTypeEnum(AdminTypeEnum.getEnumByType(this.getType()))
                .setPhone(this.phone);

    }

    public String getAccount() {
        return account;
    }

    public AdminRegisterVO setAccount(String account) {
        this.account = account;
        return this;
    }

    public String getPassword() {
        return password;
    }

    public AdminRegisterVO setPassword(String password) {
        this.password = password;
        return this;
    }

    public String getName() {
        return name;
    }

    public AdminRegisterVO setName(String name) {
        this.name = name;
        return this;
    }

    public String getMobile() {
        return mobile;
    }

    public AdminRegisterVO setMobile(String mobile) {
        this.mobile = mobile;
        return this;
    }

    public String getPhone() {
        return phone;
    }

    public AdminRegisterVO setPhone(String phone) {
        this.phone = phone;
        return this;
    }

    public Integer getType() {
        return type;
    }

    public AdminRegisterVO setType(Integer type) {
        this.type = type;
        return this;
    }
}
